#include <bits/stdc++.h>
using namespace std;
struct text{
    int id, c, m, e, zong;
}a[305];
bool cmp(text x, text y){
    if (x.zong != y.zong) return x.zong > y.zong;
    if (x.c != y.c) return x.c > y.c;
    return x.id < y.id;
}
int main(){
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i].c >> a[i].m >> a[i].e;
        a[i].id = i;
        a[i].zong = a[i].c + a[i].m + a[i].e;
    }
    sort(a + 1, a + n + 1, cmp);
    for (int i = 1;i <= 5; i++){
        cout << a[i].id << " " << a[i].zong << endl;
    }
    return 0;
}